//author:jxxgridBody
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import mall_activityBox from "../../views/mall/mall_activityBox.vue";
let extension = {
  components: {
    //动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
    gridBody: mall_activityBox,
    gridFooter: "",
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: "",
    modelBody: "",
    modelFooter: ""
  },
  buttons: {
    view: [
      {
        name: "新建",
        icon: "md-add",
        value: "XJ",
        class: "",
        type: "error",
        index: 1, //显示的位置
        onClick: function () {
          this.$refs.gridBody.model = true;
          this.$refs.gridBody.title = "新建";
          this.$refs.gridBody.tableData = []
          this.$refs.gridBody.formFields1.c_name = "";
          this.$refs.gridBody.formFields1.groupsize = "";
          this.$refs.gridBody.formFields1.fromId = "";
          this.$refs.gridBody.formFields1.start_time = "";
          this.$refs.gridBody.formFields1.end_time = "";
          this.$refs.gridBody.formFields1.timeContainer = [];
          this.$refs.gridBody.formFields1.c_type = "";
          this.$refs.gridBody.formFields1.distributionid = "";
          this.$refs.gridBody.formFields1.isShow = 1;
          this.$refs.gridBody.formFields2.c_remark = "";
          this.$refs.gridBody.formFields2.sellingRulesid = "";
          this.$refs.gridBody.formFields2.refundrulesid = "";
          this.$refs.gridBody.formFields2.verificationrulesid = "";
          this.$refs.gridBody.formFields3.groupsize = "";
          this.$refs.gridBody.formFields3.purchaseseparately = "";
          this.$refs.gridBody.formFields3.virtualclustering = "";
          this.$refs.gridBody.formFields3.maximumvirtualnumber = "";
          this.$refs.gridBody.formFields3.attendancecarddisplay = "";
          this.$refs.gridBody.formFields3.groupeffectivetime = "";
          this.$refs.gridBody.formFields4.preferentialtype = "";
          this.$refs.gridBody.formFields4.c_remark = "";
          this.$refs.gridBody.formFieldszt.isSelect = "";
          this.$refs.gridBody.formFieldszt.groupsize = "";
          this.$refs.gridBody.formFieldszt.groupsizeMax = "";
          this.$refs.gridBody.formFieldszt.groupeffectivetime = "";
        }
      },
      {
        name: "编辑",
        icon: "md-create",
        value: "BJ",
        class: "",
        type: "success",
        index: 2,
        onClick: function () {
          if (this.getSelectRows().length == 1) {
            let row = this.getSelectRows()[0];
            console.log(row)
            this.$refs.gridBody.model = true;
            this.$refs.gridBody.title = "编辑";
            this.getRow(row, 1);
          } else {
            this.$error("只能选中一行进行编辑");
          }
        }
      },
      {
        name: "删除",
        icon: "md-close",
        value: "DEL",
        class: "",
        type: "warning",
        index: 3,
        onClick: function () {
          if (this.getSelectRows().length == 1) {
            let row = this.getSelectRows()[0];
            let params = { ids: [row.c_id] };
            this.$confirm("确定要删除选择的数据吗?", "删除警告", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              // 删除接口
              this.http
                .post("/api/mall_activity/DelActivity", params)
                .then(res => {
                  if (res.status) {
                    this.$Message.error(res.message);
                  } else {
                    this.$Message.success(res.message);
                    this.refresh();
                  }
                  this.model = false;
                });
            });
          } else {
            this.$error("请选择要删除的行");
          }
        }
      }
    ],
    box: [],
    detail: []
  }, //扩展的按钮
  methods: {
    //事件扩展
    onInit () {
      this.$store.getters.data().viewPageTest = this;
      this.single = true;
      this.columns.push({
        field: "",
        title: "操作",
        type: "string",
        width: 100,
        fixed: "right",
        align: "",
        render: (h, { row, column, index }) => {
          return h("div", {}, [
            h(
              "a",
              {
                style: {},
                on: {
                  click: () => {
                    this.$refs.gridBody.model = true;
                    this.$refs.gridBody.title = "查看";
                    this.getRow(row, 0);
                  }
                }
              },
              "查看"
            )
          ]);
        }
      });
    },
    searchBefore (param) {
      let wheres = {
        name: "c_type",
        value: "8",
        displayType: "no"
      };
      param.wheres.push(wheres);
      return true;
    },
    rowClick ({ row, column, event }) {
      //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    getproList (id, memberphones, n) {
      let options = {
        "order": "desc",
        "page": 1,
        "rows": 100,
        "sort": "membertypeid",
        "value": id,
        "wheres": "[]"
      }
      this.http.post("/api/MebAccount/getPageData", options).then(res => {
        if (res.rows.length && res.rows.length != 0) {
          let productsList = res.rows.map((i) => {
            return {
              label: i.member_name || "",
              value: i.memberid,
              key: i.member_phone,
              disabled: !n,
            }
          })
          this.$refs.gridBody.productsList = productsList;
          if (memberphones != "") {
            this.$refs.gridBody.memberphones = memberphones.split(",");
          }
        }
      });
    },
    getRow (v, n) {
      console.log(v, "v")
      this.$refs.gridBody.formFields1.timeContainer = [v.start_time, v.end_time];
      let params = {
        page: 1,
        rows: 30,
        order: "desc",
        wheres: "[]",
        value: v.c_id
      };
      this.http.post("api/mall_activity/getDetailPage", params).then(res => {
        this.$refs.gridBody.ZB = v;
        if (res.rows.length) {
          res.rows.map(_ => {
            if (_.pic_path) {
              _.pic_path = _.pic_path.split(',')
            } else {
              _.pic_path = []
            }
          })
        }
        this.$refs.gridBody.goodsListInfo = res.rows;
      });
      this.$refs.gridBody.formFields1.distributionid = v.distributionid.toString();
      this.$refs.gridBody.formFields1.c_name = v.c_name;
      this.$refs.gridBody.formFields1.start_time = v.start_time;
      this.$refs.gridBody.formFields1.end_time = v.end_time;
      this.$refs.gridBody.formFields1.c_type = v.c_type.toString();
      this.$refs.gridBody.formFields1.isShow = v.isShow;
      switch (v.c_type) {
        case 0:
          this.$refs.gridBody.formFields2.refundrulesid = v.refundrulesid;
          this.$refs.gridBody.formFields2.verificationrulesid =
            v.verificationrulesid;
          this.$refs.gridBody.formFields2.sellingRulesid = v.sellingRulesid;
          this.$refs.gridBody.formFields2.c_remark = v.c_remark;
          break;
        case 1:
          this.$refs.gridBody.formFields3.groupsize = v.groupsize;
          this.$refs.gridBody.formFields3.purchaseseparately =
            v.purchaseseparately;
          this.$refs.gridBody.formFields3.virtualclustering =
            v.virtualclustering;
          this.$refs.gridBody.formFields3.maximumvirtualnumber =
            v.maximumvirtualnumber;
          this.$refs.gridBody.formFields3.attendancecarddisplay =
            v.attendancecarddisplay;
          this.$refs.gridBody.formFields3.groupeffectivetime =
            v.groupeffectivetime;
          this.$refs.gridBody.formFields2.refundrulesid = v.refundrulesid;
          this.$refs.gridBody.formFields2.verificationrulesid =
            v.verificationrulesid;
          this.$refs.gridBody.formFields2.sellingRulesid = v.sellingRulesid;
          break;
        case 2:
          this.$refs.gridBody.formFields4.preferentialtype = v.preferentialtype.toString();
          this.$refs.gridBody.setprefreialtems(JSON.parse(v.preferentialterms));
          this.$refs.gridBody.formFields4.c_remark = v.c_remark;
          break;
        case 3:
          this.$refs.gridBody.formFields4.preferentialtype = v.preferentialtype.toString();
          this.$refs.gridBody.setprefreialtems(JSON.parse(v.preferentialterms));
          this.$refs.gridBody.formFields4.c_remark = v.c_remark;
          break;
        case 5:
          this.$refs.gridBody.tableData = JSON.parse(v.rechargeRules)
          break;
        case 6:
          this.$refs.gridBody.tableData = JSON.parse(v.rechargeRules)
          break;
        case 7:
          this.$refs.gridBody.tableData = JSON.parse(v.rechargeRules)
          break;
        case 8:
          this.getproList(v.membertypes, v.memberphones, n);
          this.$refs.gridBody.formFields1.groupsize = v.groupsize;
          if (v.membertypes != "") { this.$refs.gridBody.formFields1.membertype = v.membertypes.split(",").map((item) => item * 1) }
          // console.log(this.$refs.gridBody.formFields1.membertype,"this.$refs.gridBody.formFields1.membertype")
          // Number(v.membertypes) [45,47,44]
          // if(v.membertypes!=""){this.$refs.gridBody.formFields1.membertype= v.membertypes.split(",");}
          this.$refs.gridBody.formFields2.refundrulesid = v.refundrulesid;
          this.$refs.gridBody.formFields2.verificationrulesid = v.verificationrulesid;
          this.$refs.gridBody.formFields2.sellingRulesid = v.sellingRulesid;
          this.$refs.gridBody.formFields2.c_remark = v.c_remark;
          // this.$refs.gridBody.formFields1.groupsize = v.groupsize;
          this.$refs.gridBody.formFields1.fromId = Number(v.fromId);
          break;
        case 10:
          this.$refs.gridBody.formFields2.refundrulesid = v.refundrulesid;
          this.$refs.gridBody.formFields2.verificationrulesid = v.verificationrulesid;
          this.$refs.gridBody.formFields2.sellingRulesid = v.sellingRulesid;
          this.$refs.gridBody.formFields2.c_remark = v.c_remark;
          this.$refs.gridBody.formFields1.fromId = Number(v.fromId);
          this.$refs.gridBody.formFieldszt.isSelect = v.isSelect
          this.$refs.gridBody.formFieldszt.groupsize = v.groupsize
          this.$refs.gridBody.formFieldszt.groupsizeMax = v.groupsizeMax
          this.$refs.gridBody.formFieldszt.groupeffectivetime = v.groupeffectivetime
          break;
      }
      let start_time = this.getColumns('start_time')
      let end_time = this.getColumns('end_time')
      let start_time2 = this.getColumnssc('start_time')
      let end_time2 = this.getColumnssc('end_time')
      let D = this.getColumnssc('D')
      start_time.hidden = v.c_type == 10 ? false : true
      end_time.hidden = v.c_type == 10 ? false : true
      start_time2.hidden = v.c_type == 10 ? false : true
      end_time2.hidden = v.c_type == 10 ? false : true
      D.hidden = v.c_type == 10 ? false : true
    },
    getColumns (field) {
      let option;
      this.$refs.gridBody.columns.forEach(x => {
        if (x.field == field) {
          option = x;
        }
      });
      return option;
    },
    getColumnssc (field) {
      let option;
      this.$refs.gridBody.columnsc.forEach(x => {
        if (x.field == field) {
          option = x;
        }
      });
      return option;
    },
  }
};
export default extension;
